package io.github.talelin.latticy.service.impl;

import io.github.talelin.autoconfigure.exception.NotFoundException;
import io.github.talelin.latticy.dto.banner.CreateOrUpdateBannerDTO;
import io.github.talelin.latticy.model.BannerDO;
import io.github.talelin.latticy.mapper.BannerMapper;
import io.github.talelin.latticy.service.BannerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author generator@lms
 * @since 2021-04-18
 */
@Service
public class BannerServiceImpl extends ServiceImpl<BannerMapper, BannerDO> implements BannerService {

    @Override
    public void create(CreateOrUpdateBannerDTO dto) {
        BannerDO banner = new BannerDO();
        BeanUtils.copyProperties(dto,banner);
        this.save(banner);
    }

    @Override
    public void update(CreateOrUpdateBannerDTO dto, Integer id) {
        BannerDO banner = this.getById(id);
        if (banner == null) {
            throw new NotFoundException(30000);
        }
        BeanUtils.copyProperties(dto,banner);
        this.updateById(banner);
    }
}
